package com.juyu.miliao.api.dao.redis;

import com.juyu.miliao.api.util.RedisKeys;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * wbf
 * 能量redis
 */
@Repository
public class EnergyLevelRedisDao {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    public void addEnergyLevelByType(int type ,long userId ,int energy){
        stringRedisTemplate.opsForHash().put(RedisKeys.HASH_ENERGY_LEVEL.getValue(type),userId+"",energy+"");
    }

    public void incrementEnergyLevelByType(int type ,long userId ,int energy){
        stringRedisTemplate.opsForHash().increment(RedisKeys.HASH_ENERGY_LEVEL.getValue(type),userId+"",energy);
    }

    public Boolean hasKeyEnergyLevelByType(int type ,long userId ){
        return stringRedisTemplate.opsForHash().hasKey(RedisKeys.HASH_ENERGY_LEVEL.getValue(type),userId+"");
    }

    public int getEnergyLevelByType(int type ,long userId){
        Object temp = stringRedisTemplate.opsForHash().get(RedisKeys.HASH_ENERGY_LEVEL.getValue(type),userId+"");
        if(temp == null){
            return 0;
        }
        return Integer.parseInt(temp.toString());
    }

    public Boolean isMember11UserGrade(long userId){
        return stringRedisTemplate.opsForSet().isMember("user11GradeSystemMessage",userId+"");
    }

    public void add11UserGrade(long userId){
        stringRedisTemplate.opsForSet().add("user11GradeSystemMessage",userId+"");
    }
}
